/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package assignment_cp3120.ucm;

import assignment_cp3120.dataObjects.AllLocations;
import assignment_cp3120.manager.createflights.CreateFlightsModel;
import assignment_cp3120.manager.createflights.CreateFlightsView;
import java.sql.Date;
import java.sql.Time;

/**
 * PRECONDITION: user has entered flight details and pressed create button
 * 1.System takes flights from view and puts them in the model
 * 2.System adds flight to the database
 * 3.System clears the view
 * 
 * POSTCONDITION: flight added to database
 * 
 * @author Richard Irons
 */
public class UCCreateFlight implements UseCaseController {
    private CreateFlightsModel model;
    private CreateFlightsView view;
    
    public UCCreateFlight() {
        this(new CreateFlightsModel(),new CreateFlightsView());
    }

    public UCCreateFlight(CreateFlightsModel model,CreateFlightsView view) {
        this.model = model;
        this.view = view;
    }
    
    public void run() {
        //* 1.System takes flights from view and puts them in the model
        viewToModel();        
        //* 2.System adds flight to the database
        System.out.println(model.getNewFlight().getFlight_id());
        model.addFlight();
        //* 3.System clears the view
        view.clearView();
    }

    private void viewToModel(){
        model.generateFlightID();
        System.out.println(model.getNewFlight().getFlight_id());
        model.setDepID(AllLocations.getLocationIDFromName(view.getDepName()));
        model.setDestID(AllLocations.getLocationIDFromName(view.getDestName()));
        model.setDate(Date.valueOf(view.getDate()));
        model.setArrTime(Time.valueOf(view.getArrTime()));
        model.SetDepTime(Time.valueOf(view.getDepTime()));
        model.setFlightCapacity(view.getCapacity());
        model.setFlightPrice(view.getPrice());
    }
    
}
